import { Store } from "vuex";
import { State, AccountInfo } from "@/store/type";
import { toRaw, reactive, computed, ref } from "vue";
import _ from "lodash";
//登录表单
export const useLoginFrom = (store: Store<State>) => {
  const _loginForm: AccountInfo = store.state.accountInfo
    ? _.cloneDeep(toRaw(store.state.accountInfo))
    : {
        account: "",
        password: "",
      };
  const loginForm = reactive(_loginForm);

  const loginEnable = computed(() => {
    return loginForm.account && loginForm.password ? true : false;
  });
  return {
    loginForm,
    loginEnable,
  };
};
//记住登录账号
export const useAccountLock = (store: Store<State>) => {
  const accountLock = ref<boolean>(store.state.accountInfo ? true : false);
  const accountLockChange = (value: boolean) => {
    accountLock.value = value;
  };
  return {
    accountLock,
    accountLockChange
  }
};
